import { ThemeContext } from '@/Context/ThemeContext';
import React, { useState, useEffect } from 'react';

// 定义 ThemeContext 的类型

// ThemeProvider 组件
export const ThemeProvider = ({ children }: { children: React.ReactNode }) => {
  const [theme, setThemeState] = useState<string>(() => {
    // 初始化时从 localStorage 获取主题，或默认为 'light'
    return localStorage.getItem('theme') || 'light';
  });

  useEffect(() => {
    // 每次主题变化时更新到 localStorage
    localStorage.setItem('theme', theme);
  }, [theme]);

  return (
    <ThemeContext.Provider value={{ theme, setTheme: setThemeState }}>
      {children}
    </ThemeContext.Provider>
  );
};
